using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using DTO;
using BUS;
using Utility;
public partial class admin_A_NhanVien_update : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

        if (!IsPostBack)
        {
            LoadData();
            LoadDropDownList();
        }
    }
    private void LoadDropDownList()
    {
        PhanQuyen_QuanLyColection quanlyCollection = PHANQUYEN_QUANLY_BUS.GetAll();
        ddl_quyen.DataTextField = tbPhanQuyen_QuanLyColumns.TenQuyen.ToString();
        ddl_quyen.DataValueField = tbPhanQuyen_QuanLyColumns.MaQuyen.ToString();
        ddl_quyen.DataSource = quanlyCollection;
        ddl_quyen.DataBind();
        ddl_quyen.Items.Insert(0, new ListItem("All", "0"));
    }
    private void LoadData()
    {
        try
        {
            //string tendangnhap = Session["TaiKhoan"].ToString();
            //if (tendangnhap != "")
            //{
            //    lit_tennguoidung.Text = Session["TaiKhoan"].ToString();

            //}
            //else
            //{
            //    Session["taikhoan"] = "";
            //}

            int id = int.Parse(Request.QueryString["id"].ToString());
            txt_Manv.Text = id.ToString();

            NhanVien_DTO nhanvien = NHANVIEN_BUS.GetByID(id);
            txt_Tennv.Text = nhanvien.TenNV;
            txt_mk.Text = nhanvien.MatKhau;
            txt_taiKhoan.Text = nhanvien.TaiKhoan;
            ddl_quyen.SelectedValue = nhanvien.MaQuyen.ToString();
            txt_daichi.Text = nhanvien.DiaChi;
            txt_dienthoai.Text = nhanvien.DienThoai;
            txt_mail.Text = nhanvien.Email;
        }
        catch
        {
            Response.Redirect("~/admin/A_nhanvien.aspx");
        }
    }
    protected void btn_Update_Click(object sender, EventArgs e)
    {
        try
        {
            int id = int.Parse(Request.QueryString["id"].ToString());
            NhanVien_DTO nhanvien = NHANVIEN_BUS.GetByID(id);
            nhanvien.MaNV = int.Parse(txt_Manv.Text);
            nhanvien.TenNV = txt_Tennv.Text;
            nhanvien.MatKhau = txt_mk.Text;
            nhanvien.TaiKhoan = txt_taiKhoan.Text;
            nhanvien.MaQuyen = int.Parse(ddl_quyen.SelectedValue);
            nhanvien.DiaChi = txt_daichi.Text;
            nhanvien.DienThoai = txt_dienthoai.Text;
            nhanvien.Email = txt_mail.Text;

            NHANVIEN_BUS.update(nhanvien);
            Response.Redirect("~/admin/A_nhanvien.aspx");
        }
        catch (Exception ex)
        {
            Response.Redirect("~/admin/A_nhanvien.aspx");

        }
        Response.Redirect(Request.RawUrl);

    }
}
